﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!--自适应界面,如果出现,在某些设备出现界面偏小的话,检查一下有没有加入这句 -->
    <meta http-equiv="Content-type" name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">
    <link rel="stylesheet" href="../../../js/jqmobile/jquery.mobile-1.4.5.min.css" />
    <link href="../../../js/layer_mobile/need/layer.css" rel="stylesheet" />
    <!--<script src="../js/jquery.js"></script>-->
    <script src="../../../js/jquery.min2.1.4.js"></script>
    <script src="../../../js/jqmobile/jquery.mobile-1.4.5.min.js"></script>
    <script src="../../../js/cordova-1.5.0.js"></script>
    <script src="../../../js/layer_mobile/layer.js"></script>
    <script src="../../../js/jshelp.js"></script>
    <script>
        //$(document).on("pagecreate", "#pageone", function () {
        //    $(document).on("scrollstart", function () {
        //        alert("开始滚动!");
        //    });
        //});
        //接受传参
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return unescape(decodeURI(r[2])); return null; //返回参数值
        }
        var customerCode = getUrlParam('customerCode');
        var mobile = getUrlParam('mobile');
        function tz(lx) {
            if (lx == "主页") {
                location.href = "..\\main.html?mobile=" + mobile + "&customerCode=" + customerCode;
            }
            else if (lx == "申请") {
                location.href = "..\\TransferRequest\\sq_list.html?mobile=" + mobile + "&customerCode=" + customerCode;
            }
            else if (lx == "抢单") {
                location.href = "list.html?mobile=" + mobile + "&customerCode=" + customerCode;
            }
            else if (lx == "发货") {
                location.href = "..\\TransferDeliver\\list.html?mobile=" + mobile + "&customerCode=" + customerCode;
            }
            else if (lx == "配置") {
                location.href = "..\\Config\\list.html?mobile=" + mobile + "&customerCode=" + customerCode;
            }
        }
    </script>
    <style>
        ul {
            list-style-type: none;
            padding: 0px;
            margin: 0px;
        }

            ul li {
                background-image: url(sqpurple.gif);
                background-repeat: no-repeat;
                background-position: 0px 5px;
                padding-left: 14px;
            }

        .tck {
            font: normal 12px auto "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
            color: #4f6b72;
            background: #E6EAE9;
            padding: 20px;
        }
        /*按钮*/
        .btn {
            display: block;
            position: relative;
            background: #aaa;
            padding: 10px 20px 10px 20px;
            float: left;
            color: #fff;
            text-decoration: none;
            cursor: pointer;
            font-size: 13px;
            margin: 5px;
        }

        /*数量加减*/
        * {
            margin: 0;
            padding: 0;
            border: 0;
            outline: 0
        }

        ul,
        li {
            list-style: none;
        }

        a {
            text-decoration: none;
        }

            a:hover {
                cursor: pointer;
                text-decoration: none;
            }

            a:link {
                text-decoration: none;
            }

        img {
            vertical-align: middle;
        }
        /*数量加减start*/
        .btn-numbox {
            overflow: hidden;
            margin-top: 20px;
        }

            .btn-numbox li {
                float: left;
            }

                .btn-numbox li .number,
                .kucun {
                    display: inline-block;
                    font-size: 12px;
                    color: #808080;
                    vertical-align: sub;
                }

            .btn-numbox .count {
                overflow: hidden;
                margin: 0 16px 0 -20px;
            }

                .btn-numbox .count .num-jian,
                .input-num,
                .num-jia {
                    display: inline-block;
                    width: 28px;
                    height: 28px;
                    line-height: 28px;
                    text-align: center;
                    font-size: 18px;
                    color: #999;
                    cursor: pointer;
                    border: 1px solid #e6e6e6;
                }

                .btn-numbox .count .input-num {
                    width: 35px;
                    height: 30px;
                    color: #333;
                    border-left: 0;
                    border-right: 0;
                }
        /*数量加减end*/
        .ui-listview > p {
            white-space: normal;
        }
        /*店铺名称单号行*/
        div#findstorename.ui-grid-a .ui-block-a {
            width: 50%
        }

        div#findstorename.ui-grid-a .ui-block-b {
            width: 50%
        }
        /*联系人联系方式行*/
        div#findlxr.ui-grid-a .ui-block-a {
            width: 50%
        }

        div#findlxr.ui-grid-a .ui-block-b {
            width: 50%
        }
        /*品名行*/
        div#findpm.ui-grid-a .ui-block-a {
            width: 50%
        }

        div#findpm.ui-grid-a .ui-block-b {
            width: 50%
        }
        /*尺码颜色数量行*/
        div#findcmys.ui-grid-a .ui-block-a {
            width: 40%
        }

        div#findcmys.ui-grid-a .ui-block-b {
            width: 30%
        }

        div#findcmys.ui-grid-a .ui-block-c {
            width: 30%
        }

        #controlgroupid .ui-controlgroup-controls {
            width: 100%;
        }

        #controlgroupid a {
            width: 25%;
            box-sizing: border-box;
        }

    </style>
</head>
<body>
    <div data-role="page" id="pageone">
        <div data-role="header" data-position="fixed">
            <h1>抢单列表</h1>
            <a href="#" class="ui-btn-left" data-rel="back">返回</a>
        </div>
        <div data-role="content" id="main3Content">
            <ul id="thelist" data-role="listview" data-split-icon="gear" data-split-theme="d"
                data-filter="true" data-inset="true" data-filter-placeholder="全局搜索"></ul>
        </div>
        <div data-role="footer" data-position="fixed">
            <div data-role="navbar">
                <ul id="navbarlist">
                    <li><a href="#" onclick="tz('主页')" data-role="button" data-icon="home" data-iconpos="top">首页</a></li>
                    <li><a href="#" onclick="tz('申请')" data-role="button" data-icon="plus" data-iconpos="top">调拨申请</a></li>
                    <li><a href="#" onclick="tz('抢单')" data-role="button" data-icon="shop" data-iconpos="top">调拨抢单</a></li>
                    <li><a href="#" onclick="tz('发货')" data-role="button" data-icon="navigation" data-iconpos="top">调拨发货</a></li>
                    <li><a href="#" onclick="tz('配置')" data-role="button" data-icon="gear" data-iconpos="top">设置</a></li>
                </ul>
            </div>
        </div>
    </div>
    <!--<script src="../../../layuiadmin/layui/layui.js"></script>-->
    <script>
        var clickCount = 1;
        //加载商品列表
        $(function () {
            if (mobile == "" || mobile == undefined || mobile == null) {
            } else {
                //var loginLoadIndex = layer.load(2);
                $.ajax({
                    type: "get",
                    async: false,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
                    url: "ashx/list.ashx?type=get_Snatch_list&customerCodes=" + customerCode + "&mobiles=" + mobile + "&a=" + Math.random(),
                    data: {},
                    dataType: "json",        //返回数据形式为json
                    success: function (data) {
                        var str = "";
                        if (data.item.length > 0) {
                            for (var i = 0; i < data.item.length; i++) {
                                str += '<li>';
                                str += '<div id="findstorename" class="ui-grid-a">';
                                str += '<div class="ui-block-a">';
                                str += '<h3> ' + data.item[i].docno + '</h3>';
                                str += '</div>';
                                str += '<div class="ui-block-b">';
                                str += '<p>' + data.item[i].createtime + '</p>';
                                str += '</div>';
                                str += '</div>';
                                str += '<div class="ui-grid-a">';
                                str += '<p style="white-space:normal;">收货地址：' + data.item[i].takeaddress + '</p>';
                                str += '</div>';
                                str += '<div class="ui-grid-a">';
                                str += '<p style="white-space:normal;color:red;">备注：' + data.item[i].remark + '</p>';
                                str += '</div>';
                                str += '<div id="findlxr" class="ui-grid-a">';
                                str += '<div class="ui-block-a">';
                                str += '<p>联系人：' + data.item[i].takeman + '</p>';
                                str += '</div>';
                                str += '<div class="ui-block-b">';
                                str += '<p>联系方式：' + data.item[i].takephone + '</p>';
                                str += '</div>';
                                str += '</div>';
                                str += '<hr>';
                                str += '<div id="findpm" class="ui-grid-a">';
                                str += '<div class="ui-block-a">';
                                str += '<h3> ' + data.item[i].value + '</h3>';
                                str += '</div>';
                                str += '<div class="ui-block-b">';
                                str += '<p>' + data.item[i].name + '</p>';
                                str += '</div>';
                                str += '</div>';

                                str += '<div id="findcmys" class="ui-grid-a">';
                                str += '<div class="ui-block-a">';
                                str += '<p>颜色：' + data.item[i].ys + '</p>';
                                str += '</div>';
                                str += '<div class="ui-block-b">';
                                str += '<p>尺码：' + data.item[i].cmwm + '</p>';
                                str += '</div>';
                                str += '<div class="ui-block-c">';
                                str += '<p>数量：' + data.item[i].qdsl + '</p>';
                                str += '</div>';
                                str += '</div>';
                                str += '<div data-role="navbar">';
                                str += '<ul>';
                                str += '<li><a href="" style="color:white;background-color:crimson;width:50%;float:right;" onclick="snatch(' + data.item[i].id + ',' + data.item[i].qdsl + ',' + data.item[i].request_storecode + ')">抢单</a></li>';
                                str += '</ul>';
                                str += '</div>';
                                str += '</li>';
                            }
                        }
                        else {
                            //提示
                            //layer.open({
                            //    content: "无数据!"
                            //    , skin: 'msg'
                            //    , time: 2 //2秒后自动关闭
                            //});
                            str += '<li>';
                            str += '<h3 style="text-align:center;color:red;" >无数据</h3>';
                            str += '</li>';
                        }
                        $("#thelist").html(str);
                        //解决列表样式丢失！
                        $("#thelist").trigger('create');
                        $("#thelist").listview("refresh");
                        //layer.close(loginLoadIndex);
                    }
                });
            }
        })
        
        function fabu(ids) {
            location.href = "sq_edit.html?id=" + ids + "&mobile=" + mobile + "&customerCode=" + customerCode;

        }
        //修改
        function update(id) {
            //跳转修改
            location.href = "product_update.html?ids=" + id;
        }
        function snatchsave(id, kcsl) {
            debugger
            var sl = $("#input-num").val();//数量
            if (parseInt(sl) > parseInt(kcsl)) {
                layer.open({
                    content: "抢单数量不得大于需求数量!"
                    , skin: 'msg'
                    , time: 2 //2秒后自动关闭
                });
            }
            else if (parseInt(sl) == 0) {
                layer.open({
                    content: "数量不得为0!"
                    , skin: 'msg'
                    , time: 2 //2秒后自动关闭
                });
            } else {
                //防止多次点击
                if (clickCount >= 2) {
                    return false;
                }
                else {
                    $.ajax({
                        type: "post",
                        async: true,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
                        url: "ashx/list.ashx?type=snatchsave",
                        data: { ids: id, sl: parseInt(sl), mobiles: mobile, customerCodes: customerCode },
                        dataType: "json",        //返回数据形式为json
                        success: function (data) {
                            if (data.flag == "True") {
                                clickCount++;
                                //提示
                                layer.open({
                                    content: "抢单成功，请尽快发货并到调拨发货中填写快递单号等信息!"
                                    , skin: 'msg'
                                    , time: 3 //5秒后自动关闭
                                    , end: function (index) {
                                        layer.close(index);
                                        location.reload();
                                    }
                                });

                                //询问框
                                //layer.open({
                                //    content: data.remsg + '，还要继续抢单吗？'
                                //    ,btn: ['不要', '继续']
                                //    ,yes: function (index) {
                                //        location.reload();
                                //        layer.close(index);
                                //    }
                                //});
                            } else {
                                //询问框
                                //提示
                                layer.open({
                                    content: data.remsg
                                    , skin: 'msg'
                                    , time: 2 //2秒后自动关闭
                                });
                            }
                        }
                    });
                }
            }

        }
        //抢单
        function snatch(id, kc, requeststore) {
            if (requeststore == customerCode) {
                //提示
                layer.open({
                    content: "不能抢自己发布的商品!"
                    , skin: 'msg'
                    , time: 2 //2秒后自动关闭
                });
            } else {
                var str = '';
                str += '<ul class="btn-numbox" >';
                str += ' <li><span class="number">数量</span></li>';
                str += ' <li> <ul class="count">';
                str += '  <li><span id="num-jian" class="num-jian">-</span></li>';
                str += '  <li><input type="text" class="input-num" id="input-num" value="1" /></li>';
                str += ' <li><span id="num-jia" class="num-jia">+</span></li>';
                str += '  </ul> </li> <li><span class="kucun">（需求量:' + kc + '）</span></li>';
                str += ' </ul>';
                str += ' <div style="margin-left:0px;"> <input type="button" class="btn" onclick="snatchsave(\'' + id + '\',\'' + kc + '\')" value="确定"> </div>';

                layer.open({
                    type: 1
                    , content: str
                    , anim: 'up'
                    , style: 'position:fixed; bottom:0; left:0; width: 100%; height: 30%; padding:10px 0; border:none;'
                });
            }
        }
        //数字加减框
        $("body").on("click", ".num-jian", function (m) {
            var obj = $(this).closest("ul").find(".input-num");
            if (obj.val() == 1) {
                //提示
                layer.open({
                    content: "数量最小为1"
                    , skin: 'msg'
                    , time: 1 //2秒后自动关闭
                });
            } else {
                if (obj.val() <= 0) {
                    obj.val(0);
                } else {
                    obj.val(parseInt(obj.val()) - 1);
                }
                obj.change();
            }
        });
        $("body").on("click", ".num-jia", function (m) {
            var obj = $(this).closest("ul").find(".input-num");
            obj.val(parseInt(obj.val()) + 1);
            obj.change();
        });
    </script>

</body>
</html>
